<template>
  <div class="page">
    <!-- 多包裹详情 -->
    <div class="infoList">
      <!-- 商品列表 -->
      <div class="productList" v-if="dataInfo.showType == '0'">
        <div class="title">{{ $t('user.commodityList') }}</div>
        <div class="main">
          <div class="table">
            <Row class="header">
              <Col span="11">
              <div class="th">{{ $t('submitParcel.product') }}</div>
              </Col>
              <Col span="4">
              <div class="th">{{ $t('submitParcel.quantity') }}</div>
              </Col>
              <Col span="4">
              <div class="th">{{ $t('submitParcel.dimension') }}(cm)</div>
              </Col>
              <Col span="5">
              <div class="th">{{ $t('submitParcel.weight') }}(g)</div>
              </Col>
            </Row>
            <div class="table-row">
              <div class="table-body" v-for="(item, index) in parcelInfo.parcelGoodsList">
                <Row :key="index">
                  <Col span="11">
                  <div class="commodity-info">
                    <div class="commodity-left">
                      <product-picture v-if="item.mainImg" :image-list="[item.mainImg]"></product-picture>
                      <img v-else class="image" src="@/assets/images/public/default-image.png" alt="">
                    </div>
                    <div class="commodity-content">
                      <div class="title ellipsis" :title="item.subject">{{ item.subject }}</div>
                      <div class="intro ellipsis" :title="item.skuRemarks">{{ item.skuRemarks }}</div>
                    </div>
                  </div>
                  </Col>
                  <Col span="4">x {{ item.quantity }} </Col>
                  <Col span="4"> {{ item['length'] }}*{{ item.width }}*{{ item.height }} </Col>
                  <Col span="5"> {{ item.weight }} </Col>
                </Row>
              </div>
            </div>
          </div>
        </div>
      </div>
      <!-- 包裹列表 -->
      <div class="packageList" v-else>
        <div class="title">{{ $t('user.parcelList') + (index + 1) }}</div>
        <div class="main">
          <div class="packageInfo">
            <!-- <img class="image" :src="parcelInfo.parcelImg" @click="viewPicture(parcelInfo.parcelImg, 0)" alt=""> -->
            <div v-if="dataInfo.status != 'WAIT_PAYMENT' && dataInfo.status != 'WAIT_PACK'">{{ $t('user.parcelSize')
              }}(cm)：{{ parcelInfo.length }}*{{ parcelInfo.width }}*{{ parcelInfo.height }}
            </div>
            <div>{{ $t('user.parcelWeight') }}(g)：{{ parcelInfo.weight }}</div>
            <div>{{ $t('user.associatedWaybillNumber') }}：{{ dataInfo.expressOrderNo }}</div>
            <div>{{ $t('user.expressNumber') }}：{{ parcelInfo.expressNo }} <span class="pointer"
                @click="viewLogistics(parcelInfo.expressNo)" v-if="parcelInfo.expressNo">
                {{ $t('user.logisticsInfo') }}</span></div>
            <div><span>{{ dataInfo.statusName }}</span></div>
          </div>
          <div class="table">
            <Row class="header">
              <Col span="11">
              <div class="th">{{ $t('user.parcelInfo') }}</div>
              </Col>
              <Col span="4">
              <div class="th">{{ $t('user.quantity') }}</div>
              </Col>
              <Col span="4">
              <div class="th">{{ $t('user.price') }}</div>
              </Col>
              <Col span="5">
              <div class="th">{{ $t('user.grossMerchandiseValue') }}</div>
              </Col>
            </Row>
            <div class="table-row">
              <div class="table-body" v-for="(item, index) in parcelInfo.parcelGoodsList" :key="index">
                <Row>
                  <Col span="11">
                  <div class="commodity-info">
                    <div class="commodity-left">
                      <product-picture v-if="item.mainImg" :image-list="[item.mainImg]"></product-picture>
                      <img v-else class="image" src="@/assets/images/public/default-image.png" alt="">
                    </div>
                    <div class="commodity-content">
                      <div class="title">{{ item.subject }}</div>
                      <div class="intro">{{ item.skuRemarks }}</div>
                    </div>
                  </div>
                  </Col>
                  <Col span="4">x {{ item.pkgQuantity }} </Col>
                  <Col span="4"> {{ dataInfo.currencySymbol }} {{ item.price }} </Col>
                  <Col span="5"> {{ dataInfo.currencySymbol }} {{ item.price | bigTimes(item.pkgQuantity) }} </Col>
                </Row>
                <div class="note" v-if="index == 0">
                  <div class="ordinary-photograph" v-if="parcelInfo.parcelImg.length > 0">
                    <div class="content">
                      <span class="label"> {{ $t('user.packageImage') }}</span>
                      <div class="image-list">
                        <img class="image" v-for="img in parcelInfo.parcelImg" :src="img" @click="viewPicture(parcelInfo.parcelImg, 0)"
                          alt="">
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>

      <!-- 运费明细 -->
      <div class="costDetails" v-if="dataInfo.status != 'INIT'">
        <div class="title">{{ $t('user.costDetails') }}</div>
        <div class="freight-detail">
          <div class="freight" v-if="dataInfo.showType == '0'">
            <div class="item">
              <span class="label"> {{ $t('user.lineFreight') }}： </span>
              <span class="value"> {{ parcelInfo.currencySymbol }} {{ parcelInfo.routeFee || parcelInfo.routeFee == 0 ?
                parcelInfo.routeFee : '--' }} </span>
            </div>
            <div class="item">
              <span class="label"> {{ $t('user.productCompensation') }}： </span>
              <span class="value"> {{ parcelInfo.currencySymbol }} {{ parcelInfo.prodDiffFee || parcelInfo.prodDiffFee
                == 0 ? parcelInfo.prodDiffFee :
                '--'
                }} </span>
            </div>
            <!-- <div class="item">
              <span class="label"> {{ $t('user.international') }}： </span>
              <span class="value"> {{ parcelInfo.currencySymbol }} {{ parcelInfo.transportAmountEnCost ||
                parcelInfo.transportAmountEnCost == 0 ?
                parcelInfo.transportAmountEnCost : '--' }} </span>
            </div> -->
          </div>
          <div class="freight" v-else>
            <div class="item">
              <span class="label"> {{ $t('user.domesticLogisticsCosts') }}： </span>
              <span class="value"> {{ parcelInfo.currencySymbol }} {{ parcelInfo.logisticsAmt || parcelInfo.logisticsAmt
                == 0 ? parcelInfo.logisticsAmt
                : '--' }} </span>
            </div>
            <div class="item">
              <span class="label"> {{ $t('user.internationalLogisticsCosts') }}： </span>
              <span class="value"> {{ parcelInfo.currencySymbol }} {{ parcelInfo.routeAmt || parcelInfo.routeAmt == 0 ?
                parcelInfo.routeAmt : '--'
                }} </span>
            </div>
            <div class="item">
              <span class="label"> {{ $t('user.addedServiceCharge') }}： </span>
              <span class="value vital"> {{ parcelInfo.currencySymbol }} {{ parcelInfo.serviceAmt ||
                parcelInfo.serviceAmt == 0 ?
                parcelInfo.serviceAmt : '--' }} </span>
            </div>
            <div class="item">
              <span class="label"> {{ $t('user.operatingCost') }}： </span>
              <span class="value"> {{ parcelInfo.currencySymbol }} {{ parcelInfo.operateAmt || parcelInfo.operateAmt ==
                0 ? parcelInfo.operateAmt :
                '--' }} </span>
            </div>
            <!-- <div class="item">
              <span class="label"> {{ $t('user.productCompensation') }}： </span>
              <span class="value"> {{ parcelInfo.currencySymbol }} {{ parcelInfo.prodDiffFee ? parcelInfo.prodDiffFee : '--'
                }} </span>
            </div>
            <div class="item">
              <span class="label"> {{ $t('user.international') }}： </span>
              <span class="value"> {{ dataInfo.currencySymbol }} {{ dataInfo.transportAmountEnCost ?
                dataInfo.transportAmountEnCost : '--' }} </span>
            </div> -->
          </div>
          <!-- v-if="dataInfo.status == 'WAIT_CONFIRM' || dataInfo.status == 'CONFIRMING'" -->
          <div class="freight">
            <!-- <div class="item">
              <div class="label">{{ $t('user.customsDeclarationCurrency') }}：</div>
              <div class="value">{{ dataInfo.declareCurrency ? dataInfo.declareCurrency : '--' }}</div>
            </div>
            <div class="item">
              <div class="label">{{ $t('user.customsDeclarationValue') }}：</div>
              <div class="value">{{ dataInfo.declareCurrency }} {{ dataInfo.declareValue ? dataInfo.declareValue : '--'
                }}</div>
            </div>
            <div class="item">
              <div class="label">{{ $t('user.customsDeclarationWeight') }}：</div>
              <div class="value">{{ dataInfo.currencySymbol }} {{ dataInfo.declareWeight ? dataInfo.declareWeight :
                '--' }}g</div>
            </div> -->
            <div class="item">
              <div class="label">{{ $t('user.taxPaymentMethod') }}：</div>
              <div class="value">{{ $t('user.recipientTax') }}</div>
            </div>
            <div class="item">
              <div class="label">{{ $t('user.packagingServiceItem') }}：</div>
              <div class="value">
                <div class="tooltip-value-wrap">
                  <Tag class="tag" v-for="item in parcelInfo.serviceItemsList" :key="item.id" color="#E76202">
                    {{ item.name }}
                    <Tooltip placement="top-start" max-width="300">
                      <div slot="content">
                        <p>{{ item.description }}</p>
                        <img width="50" :src="item.examplePicture" alt="">
                      </div>
                      <span class="iconfont icon-bangzhu"></span>
                    </Tooltip>
                  </Tag>
                </div>
              </div>
            </div>
            <!-- <div class="item">
              <div class="label">{{ $t('user.remark') }}：</div>
              <div class="value remark">{{ parcelInfo.remarks }}</div>
            </div> -->
          </div>
        </div>
      </div>

      <!-- 物流信息 -->
      <div class="logistics-info">
        <div class="title">{{ $t('user.logisticsInfo') }}</div>
        <div class="info">
          <div class="info-item">
            <span class="label">{{ $t('user.distributionMode') }}：</span>
            <span class="value">{{ parcelInfo.logisticsChannelName ? parcelInfo.logisticsChannelName : '--' }}</span>
          </div>
          <div class="info-item">
            <span class="label">{{ $t('user.destinationCountry') }}：</span>
            <span class="value">{{ dataInfo.orderAddress.countryText }}</span>
          </div>
        </div>
      </div>

      <!-- 费用 -->
      <div class="packageFees" v-if="dataInfo.status != 'INIT'">
        <div v-if="dataInfo.status == 'WAIT_PACK'">{{ $t('customOrder.expense') }}：</div>
        <div v-else>{{ $t('user.packageFees') }}：</div>
        <div class="fees">{{ parcelInfo.currencySymbol }} {{ parcelInfo.calculateTotalCost ||
          parcelInfo.calculateTotalCost == 0 ?
          parcelInfo.calculateTotalCost : '--' }}</div>
      </div>
    </div>

    <!--物流详情-->
    <Modal v-model="physical" class-name="vertical-center-modal" :title="$t('user.logisticsInfo')" class="physical-pop"
      :mask-closable="false">
      <div style="height: 300px;overflow: auto">
        <t-loading v-if="logisticsLoading"></t-loading>
        <Timeline v-for="item in logisticsInfo" :key="item.thirdOrderNum">
          <TimelineItem v-for="(setItem, index) in item.logisticsSteps" :key="index">
            <p class="content">{{ setItem.remarks }}</p>
            <p class="time">{{ setItem.acceptTime }}</p>
          </TimelineItem>
        </Timeline>
      </div>
    </Modal>
  </div>
</template>

<script>
import {
  expressOrderQueryLogisticsTrace,
} from "@/api/expressOrder";
import TLoading from "@/components/t-loading";
import ProductPicture from "@/views/main/user/components/product-picture";
import { mapState } from "vuex";

export default {
  components: { ProductPicture, TLoading },
  props: ['dataInfo', 'index', 'parcelInfo'],
  data() {
    return {
      logisticsLoading: false,
      logisticsInfo: [], // 物流信息
      physical: false, // 查看物流弹窗
      orderList: [],
      images: []
    }
  },
  computed: {
    ...mapState({
      userInfo: state => state.user.userInfo,
      userCurrency: state => state.user.userCurrency
    })
  },
  created() {

  },
  methods: {
    viewPicture(list, index) {
      // 查看图片
      this.images = list;
      this.$viewerApi({
        images: this.images,
        options: {
          initialViewIndex: index
        }
      })
    },
    viewLogistics(id) {
      // 获取运单的物流追踪信息（国际）
      this.logisticsInfo = [];
      this.physical = true;
      this.logisticsLoading = true;
      expressOrderQueryLogisticsTrace(id).then((res) => {
        this.logisticsInfo = res.result;
        this.logisticsLoading = false;
      }).catch(() => {
        this.logisticsLoading = false;
      })
    }
  }
}
</script>

<style scoped lang="less">
.page {
  .image {
    display: block;
    height: 50px;
    max-width: 100px;
    border-radius: 4px 4px 4px 4px;
    margin-right: 10px;
  }

  .infoList {
    border-radius: 2px 2px 2px 2px;
    border: 1px solid #DCDEE2;
    width: 100%;
    padding: 0 10px;
    margin: 20px 0;

    >div>.title {
      height: 45px;
      line-height: 45px;
      // padding: 0 22px;
      font-weight: 500;
      font-size: 16px;
      color: #232323;
    }

    .main {
      border: 1px solid #DCDEE2;
      padding: 0 15px 0;

      .packageInfo {
        display: flex;
        justify-content: space-between;
        flex-wrap: nowrap;
        align-items: center;
        font-size: 14px;
        color: #232323;
        height: 62px;
        line-height: 62px;

        >div {
          flex: auto;

          &:last-child {
            text-align: right;
          }

          >span {
            color: #E76202;
          }

          .pointer {
            cursor: pointer;
          }
        }
      }

      .table {
        margin: 0 -15px;
        border-bottom: 1px solid #DCDEE2;

        &:last-child {
          border: 0;
        }

        .header {
          padding: 0 27px;
          height: 40px;
          line-height: 40px;
          background: #F8F8F9;
          font-weight: 500;
          font-size: 14px;
          color: #232323;
        }

        .table-row {
          padding: 0 15px;

          .table-body {
            padding: 20px 0;
            border-bottom: 1px solid #DCDEE2;

            &:last-child {
              border: 0;
            }

            .commodity-info {
              display: flex;



              .commodity-content {
                font-size: 14px;
                color: #232323;
                padding: 0 20px 0 10px;
                margin-bottom: 6px;

                .intro {
                  font-size: 12px;
                  color: #666666;
                }
              }
            }

            .note {
              .ordinary-photograph {
                display: flex;
                align-items: center;
                justify-content: space-between;
                background: @t-border-color;
                padding: 12px 24px;
                margin-top: 15px;

                .content {
                  display: flex;
                  align-items: center;

                  .label {
                    color: @t-text-color;
                    font-size: 12px;
                  }

                  .image-list {
                    display: flex;
                    align-items: center;

                    .image {
                      display: block;
                      width: 56px;
                      height: 56px;
                      margin-left: 16px;
                      border-radius: 4px 4px 4px 4px;
                    }
                  }
                }

                .right {
                  .iconfont {
                    margin-left: 44px;
                    cursor: pointer;
                    color: @t-title-color;
                    font-size: 18px;
                  }
                }

              }
            }
          }
        }
      }
    }

    .freight-detail {
      display: flex;
      align-items: stretch;
      justify-content: space-between;

      .freight {
        flex: 1;
        border: 1px solid #DCDEE2;
        padding: 24px;
        font-size: 16px;
        color: #232323;
        margin-right: 11px;

        .item {
          display: flex;
          justify-content: space-between;
          margin-bottom: 15px;

          &:last-child {
            margin: 0;
          }

          .tooltip-value-wrap {
            display: flex;
            flex-wrap: wrap;

            .iconfont {
              cursor: pointer;
              font-size: 12px;
            }

            .tag {
              display: flex;
              align-items: center;
            }
          }

          .remark {
            width: 50%;
            overflow: hidden;
            text-align: right;
            white-space: normal;
            word-break: break-all;
          }
        }
      }
    }

    .logistics-info {
      margin-bottom: 10px;

      .info {
        display: flex;
        align-items: center;
        font-size: 14px;
        color: #232323;

        .info-item {
          margin-right: 20px;
        }
      }
    }

    .packageFees {
      display: flex;
      align-items: center;
      justify-content: flex-end;
      height: 84px;
      background: #f0f9ff;
      border-radius: 2px 2px 2px 2px;
      margin: 0 -10px;
      padding: 0 30px;

      .fees {
        font-weight: 700;
        font-size: 22px;
        color: #E76202;
      }
    }
  }

  .ellipsis {
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    text-overflow: ellipsis;
    white-space: normal;
  }
}
</style>